
function getIdQuery(fields){
    return fields.filter(({primaryKey})=>primaryKey)

}


module.exports = function setTable({ fields=[] }, result) {

    if(fields.length && result ){
        result.table = {}
        result.table.columns = fields.filter(({show})=>show).map(({label,tag,prop,link,showOption={}})=>{
            const rst =  {
                prop,
                label,
                tag,
                ...showOption
            }
            if(link){
                const params =  getIdQuery(fields)
                // console.log(`link:${link};params:`+params.map(pk=>'`${pk}=${row[pk]}`').join('&'))
                const code =  params.map(({prop:pk})=>`${pk}=\${row['${pk}']}`).join('&')
                rst.link = 'funcString: row #---# return '+ `\`${link}?${code}\``;
            }
            return rst
        })
    }


}
